home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11080 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  79 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: mvaccaro1@aol.com (MVaccaro1)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Newbie Questions
  5. Date: 21 Mar 1996 16:15:22 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4isgta$7cr@newsbf02.news.aol.com>
  9. References: <4irpc1$b8u@GRAPEVINE.LCS.MIT.EDU>
  10. Reply-To: mvaccaro1@aol.com (MVaccaro1)
  11. NNTP-Posting-Host: newsbf02.mail.aol.com
  12.  
  13. >Question #2
  14. >
  15. >Why does the scope of the external declaration not extend beyond >the
  16. >inner block?
  17. >
  18. >{
  19. >    {
  20. >        extern E;
  21. >        E = 0;
  22. >    }
  23. >    E = 1;
  24. >}
  25.  
  26. Your declare of the external variable E is only known in the block it is
  27. declared in.  Had you wrote the code this way:
  28.  
  29. extern int E;
  30.  
  31. func( ... )
  32. {
  33.    {
  34.    E=0;
  35.    }
  36. E=1;
  37. }
  38.  
  39. E would be known to all references in the file.
  40.  
  41. Where as 
  42.  
  43. func( ... )
  44.    {
  45.    extern int E;
  46.       {
  47.       E = 0;
  48.       }
  49.    E = 1;
  50.    }
  51.  
  52. E would only be known within function.
  53.  
  54. >Question #3
  55. >
  56. >Is there any difference between these two declarations?
  57. >
  58. >   char *s1 = "hello";
  59. >   char s2[] = "hello";
  60. >
  61. >
  62. >Thanks for any help!
  63.  
  64. try this little test and tell me what happens:
  65.  
  66. main( )
  67.    {
  68.    char *s1 = "hello";
  69.    char s2[ ] = "hello";
  70.  
  71.    printf( "Sizeof s1 %d\n Sizeof s2 %d\n", sizeof s1, sizeof s2 );
  72.    return 0;
  73.    }
  74.  
  75. You may be surprised!
  76.  
  77. Mike :->
  78. Design? What design! - I've too much coding to do...
  79.